package com.xiangyun.controller;

import com.sun.javafx.collections.MappingChange;
import com.xiangyun.aop.InvokeLog;
import com.xiangyun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpSession;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

@Controller

public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(method = RequestMethod.POST,value = "/login")
    public String login(String username, String password, HttpSession session){
        //往sesson域中写入用户名用来代表登录成功
//        System.out.println(1/0);
        System.out.println(username + password);
        session.setAttribute("username",username);
        return "/WEB-INF/page/success.jsp";
    }

    @GetMapping("/helle")
    @ResponseBody
    public void hello(Model model){
        String a = userService.findAll();
        Map<String, Object> map = model.asMap();
        Set<String> keySet = map.keySet();
        Iterator<String> iterator = keySet.iterator();
        while (iterator.hasNext()){
            String key = iterator.next();
            Object value = map.get(key);
            System.out.println(key+">>>"+value);
        }
        System.out.println("controller层调用" + a);
    }
}
